import $http from "../assets/js/http";

// 出入记录查询
export async function getRecord({
  _time,
  name,
  number,
  type,
  page
}) {
  _time = JSON.stringify(_time);
  return $http.post("inout/Inout/getRecord", {
    _time,
    name,
    number,
    type,
    page
  });
}

// 获取身份证信息以及性别
export async function getFszSex(name) {
  return $http.post("inout/Inout/getFszSex", {
    name
  });
}

// 获取员工信息
export async function getPersonInfo(sfz, name, jobNumber, type) {
  return $http.post("inout/Inout/getPersonInfo", {
    sfz,
    name,
    type
  });
}

// 办理入住
export async function personCheckIn(inData) {
  // 处理时间
  inData._inTime = parseInt(inData.inTime.getTime()) / 1000;
  // 物品序列化
  let goods = "";
  for (let i = 0; i < inData._goods.length; i++) {
    // goods += "&&" + inData._goods[i];
    if (i === 0) {
      goods += inData._goods[i];
    } else {
      goods += "&&" + inData._goods[i];
    }
  }
  inData.goods = goods;
  return $http.post("inout/Inout/personCheckIn", inData);
}

// 获取住宿信息
export async function bedInfo(name) {
  return $http.post("inout/Inout/bedInfo", {
    name
  });
}

// 办理退宿
export async function personCheckOut(outData, goods) {
  // 处理时间
  outData._outTime = parseInt(outData.outTime.getTime()) / 1000;
  // 物品序列化
  outData.goods = "";
  for (let i = 0; i < outData._goods.length; i++) {
    if (i === 0) {
      outData.goods += outData._goods[i];
    } else {
      outData.goods += "&&" + outData._goods[i];
    }
  }
  for (let i = 0; i < outData.noReturn.length; i++) {
    if (i === 0) {
      outData._noReturn += outData.noReturn[i];
    } else {
      outData._noReturn += "&&" + outData.noReturn[i];
    }
  }
  // console.log(outData);
  return $http.post("inout/Inout/personCheckOut", outData);
}
